<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style>
			#qrySelectDate{
				width: 200px;
			    height: 30px;
			    border: 1px solid black;
			    line-height: 30px;
			}
			#qryCurrentDate{
				width: 200px;
			    height: 30px;
			    border: 1px solid black;
			    line-height: 30px;
			}
		</style>
	</head>
	<body>
		<div id="wrap">
			<input type="button" name="" id="week" value="一周内" />
			<input type="button" name="" id="month" value="一月内" />
			<input type="button" name="" id="threeMonth" value="三月内" />
			<div id="qrySelectDate"></div>
			<input type="button" name="" id="" value="当前时间" />
			<div id="qryCurrentDate"></div>
		</div>
		<script type="text/javascript">
			var date=new Date();
				year=date.getFullYear();
				month=date.getMonth();
				console.log(month)
				day=date.getDate();
				hour=date.getHours();
				minutes=date.getMinutes();
				second=date.getSeconds();
			document.getElementById("qryCurrentDate").innerHTML=year+'年'+(month+1)+'月'+day+'日';
			document.getElementById("week").onclick=function(){
				var beforeDate=new Date();
				beforeDate.setTime(date.getTime()-7*24*60*60*1000)
				newYear=beforeDate.getFullYear();
				newMonth=beforeDate.getMonth()+1;
				newDay=beforeDate.getDate();
				document.getElementById("qrySelectDate").innerHTML=newYear+'年'+newMonth+'月'+newDay+'日';
			}
			document.getElementById("month").onclick=function(){
				if (Number(month)>0) {
					beforeDate=new Date(year,Number(month),day,hour,minutes,second);	
					newYear=beforeDate.getFullYear();
					newMonth=beforeDate.getMonth();
					newDay=beforeDate.getDate();
					document.getElementById("qrySelectDate").innerHTML=newYear+'年'+newMonth+'月'+newDay+'日';
				} else{
					newYear=Number(year)-1;
					newMonth=12;
					newDay=day;
					document.getElementById("qrySelectDate").innerHTML=newYear+'年'+newMonth+'月'+newDay+'日';
				}
				
			}
			document.getElementById("threeMonth").onclick=function(){
				var beforeDate=''
				if (Number(month)>2) {
					beforeDate=new Date(year,Number(month)-2,day,hour,minutes,second);	
					newYear=beforeDate.getFullYear();
					newMonth=beforeDate.getMonth();
					newDay=beforeDate.getDate();
					document.getElementById("qrySelectDate").innerHTML=newYear+'年'+newMonth+'月'+newDay+'日';
				} else{
					newYear=newYear=Number(year)-1;
					newMonth=10+Number(month);
					newDay=day;
					document.getElementById("qrySelectDate").innerHTML=newYear+'年'+newMonth+'月'+newDay+'日';
				}
				
			}
		</script>
	</body>
</html>
